package LeetCode;

public class LC_572_SubtreeofAnotherTree {

    public static void main(String[] args) {

    }

    class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }

    class Solution {
        boolean isSubtree(TreeNode s, TreeNode t) {
            return s != null && (isSame(s, t) || isSubtree(s.left, t) || isSubtree(s.right, t));
        }

        private boolean isSame(TreeNode s, TreeNode t) {
            return s == null && t == null || s != null && t != null && s.val == t.val && isSame(s.left, t.left) && isSame(s.right, t.right);
        }
    }

}